@extends('admin.base')
@section('title', '商城入口类型列表')
@section('content')
 <div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/shop/index')}}" style="cursor:pointer;" ><cite>入口类型列表</cite></a>;
            </span>
        </div>
    </fieldset>
    <div class="layui-card-header">
      <div>
        <span class="pull-left">
          <div class="layui-form">
            <div class="layui-form-item">
              <div class="layui-inline">     
                <label class="layui-form-label">关键字</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="sub_keywords" name="keywords" value="{{ isset($request['keywords']) ? $request['keywords'] : '' }}"  placeholder="入口类别">
                </div>
                
                {{--<label class="layui-form-label" >时间</label>--}}
                {{--<div class="layui-input-inline">--}}
                    {{--<input  type="text" class="layui-input" class="jeinput" id="test11" placeholder="创建时间(年月日~年月日)" name="month" value="{{ isset($request['month']) ? $request['month'] : '' }}" readonly>--}}
                {{--</div>--}}
                <div class="layui-input-inline">
                  <button class="layui-btn" lay-submit lay-filter="selectsub" >搜索</button>
                </div>
              </div>
            </div>
          </div>
        </span>
            
       <span class="pull-right">
            <button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/shophome/add')}}','','添加');">
                <i class="layui-icon">&#xe608;</i> 添加
            </button>
        </span>
      </div>
    </div>

    <div class="layui-card-body">
        <style>
            table tr td.tc,table tr th.tc {
                text-align: center;
                cursor:default;
            }
        </style>
        <table class="layui-table" lay-even lay-size="">
            <colgroup>
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
            </colgroup>
            <thead>
                <tr>
                    <th class="tc">ID</th>
                    <th class="tc">入口类别</th>
                    <th class="tc">图片</th>
                    <th class="tc">状态</th>
                    <th class="tc">排序</th>
                    <th class="tc">创建时间</th>
                    <th class="tc">操作</th>
                </tr>
                <tbody>
                    @if($list->isEmpty())
                        <tr>
                            <td colspan="11" class="tc">暂无数据</td>
                        </tr>
                    @else
                        @foreach ($list as $v)
                            <tr>
                                <td class="tc">{{ $v->id }}</td>
                                <td class="tc">{{ $v['name'] }}</td>
                                <td class="tc"><img src="{{$v['picname']}}"></td>
                                
                                <td class="tc">
                                    <form class="layui-form " action="">
                                        <input type="checkbox" @if($v['state']==1) checked @endif name="" lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用" value="{{ $v['id'] }}">
                                    </form>
                                </td>
                                <td class="tc"><a href="javascript:void(0);"
                                       onclick="sorts({{$v->id}},{{$v->sort}})">{{$v->sort}}</a></td>
                                <td class="tc">{{$v['created_at']}}</td>
                                <td class="tc">
                                    <div class="layui-btn-group" >
                                        <button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/shophome/edit')}}','{{$v['id']}}','详情');" >编辑</button>
                                        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="del('{{url('admin/shophome/del')}}','{{$v->id}}');" >删除</button>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    @endif
                </tbody>
            </thead>
        </table>
        <!-- 分页 -->
        <div class="sabrosus" >{{ $page }}</div>
        <!-- {{$list->total()}} -->
    </div>

 </div>
@endsection
@section('js')
    <script>
        layui.use('form', function(){
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function(data){
                let keywords = $('#sub_keywords').val();//关键字
                let month = $("#test11").val();//时间
                // let level = $("#level option:selected").val();//级别
                // layer.msg(keywords+"|"+month+"|"+level)
                location.href = "{{url('admin/shophome/index')}}"+"?keywords="+keywords;
                return false;
            });

            //监听指定开关
            form.on('switch(switchTest)', function(data){
                var id = data.value;

                if(data.elem.checked){
                    var state = 1;//启用
                }else{
                    var state = 2;//禁用               
                }
                ajax('/admin/shophome/up_state',{id:id,state:state});
            });
        });

        function sorts(id, num) {
            layer.prompt({
                formType: 3,
                value: num,
                title: '修改排序'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/shophome/update_sort", {
                    id: id,
                    sort: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }
                })
            });
        }
    </script>
@endsection